home *** CD-ROM | disk | FTP | other *** search
- unit DrBobDOS;
- { (c) 1997 by Bob Swart (aka Dr.Bob - www.drbob42.com) }
- interface
- uses
- SysUtils, WinTypes, WinProcs, Classes;
-
- type
- TBDosEnvironment = class(TComponent)
- public
- { Public class declarations (override) }
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
-
- private
- { Private field declarations }
- FDosEnvList: TStringList;
- procedure DoNothing(const Value: TStringList);
-
- protected
- { Protected method declarations }
- Dummy: Word;
- function GetDosEnvCount: Word;
-
- public
- { Public interface declarations }
- function GetDosEnvStr(const Name: String): String;
- { This function is a modified version of the GetEnvVar function that
- appears in the WinDos unit that comes with Delphi. This function's
- interface uses Pascal strings instead of null-terminated strings.
- }
-
- published
- { Published design declarations }
- property DosEnvCount: Word read GetDosEnvCount write Dummy;
- property DosEnvList: TStringList read FDosEnvList write DoNothing;
- end;
-
- implementation
-
- constructor TBDosEnvironment.Create(AOwner: TComponent);
- var
- P: PChar;
- begin
- inherited Create(AOwner);
- FDosEnvList := TStringList.Create;
- {$IFDEF WIN32}
- P := GetEnvironmentStrings;
- {$ELSE}
- P := GetDosEnvironment;
- {$ENDIF}
- while P^ <> #0 do
- begin
- FDosEnvList.Add(StrPas(P));
- Inc(P, StrLen(P)+1) { Fast Jump to Next Var }
- end;
- end {Create};
-
- destructor TBDosEnvironment.Destroy;
- begin
- FDosEnvList.Free;
- FDosEnvList := nil;
- inherited Destroy
- end {Destroy};
-
- procedure TBDosEnvironment.DoNothing(const Value: TStringList);
- begin
- end {DoNothing};
-
-
- function TBDosEnvironment.GetDosEnvCount: Word;
- { Returns the number of environment variables.
- }
- begin
- if Assigned(FDosEnvList) then
- Result := FDosEnvList.Count
- else
- Result := 0;
- end {GetDosEnvCount};
-
- function TBDosEnvironment.GetDosEnvStr(const Name: String): String;
- { This function is a modified version of the GetEnvVar function that
- appears in the WinDos unit that comes with Delphi. This function's
- interface uses Pascal strings instead of null-terminated strings.
- }
- var
- i: Integer;
- Tmp: String;
- begin
- i := 0;
- Result := '';
- if Assigned(FDosEnvList) then while i < FDosEnvList.Count do
- begin
- Tmp := FDosEnvList[i];
- Inc(i);
- if Pos(Name,Tmp) = 1 then
- begin
- Delete(Tmp,1,Length(Name));
- if Tmp[1] = '=' then
- begin
- Delete(Tmp,1,1);
- Result := Tmp;
- i := FDosEnvList.Count { end while-loop }
- end
- end
- end
- end {GetDosEnvStr};
- end.
-